﻿using SCM.Common;
using SCM.Common.Extensions;
using SCM.Model;
using SCM.Model.DBEntity;
using SCM.Servie.IBusiness;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace SCM.Servie.Business
{
    /// <summary>
    /// 测试报告豁免条款接口
    /// </summary>
    public class TestReportExemptionService : ITestReportExemptionService
    {
        private readonly DbContext dal = new DbContext();

        public string Add(T_TestReportExemption model)
        {
            return dal.Insertable(model).ExecuteReturnEntity().ID;
        }

        public bool Delete(List<string> ids)
        {
            return dal.Deleteable<T_TestReportExemption>().Where(p => ids.Contains(p.ID)).ExecuteCommand() > 0;
        }

        public T_TestReportExemption GetById(string id)
        {
            return dal.Get<T_TestReportExemption>(id);
        }

        public List<T_TestReportExemption> GetList(string testReportID)
        {
            Expression<Func<T_TestReportExemption, bool>> whereExp = (a) => true;
            if (!string.IsNullOrWhiteSpace(testReportID))
            {
                whereExp = whereExp.Compose((a) => a.TestReportID == testReportID, Expression.AndAlso);
            }
            return dal.Queryable<T_TestReportExemption>().Where(whereExp).ToList();
        }

        public bool Update(T_TestReportExemption model)
        {
            return dal.Modify(model);
        }
    }
}
